/*
* 优惠券退回记录
* @Author: Li Yujie
* @Date: 2020-11-14
*/
<template>
    <div class="wrapper">
        <!--筛选表单-->
        <div class="filter-view">
            <div class="header-new-box">
                <p class="header-new-box-title">退回原因</p>
                <el-select
                    v-model="filterData.back_type"
                    clearable
                    filterable
                    size="small"
                    @change="getTableData(1)"
                >
                    <el-option
                        v-for="item in reasonList"
                        :key="item.value"
                        :label="item.label"
                        :value="item.value"/>
                </el-select>
            </div>
            <div class="header-new-box">
                <p class="header-new-box-title">用户信息</p>
                <el-input
                    placeholder="请输入用户昵称/手机号/订单编号"
                    v-model="filterData.keyword"
                    suffix-icon="el-icon-search"
                    size="small"
                    clearable
                    @keydown.enter.native="getTableData(1)"
                    @blur="getTableData(1)"
                />
            </div>
        </div>
        <!--/筛选表单-->

        <!-- table -->
        <el-table
            :data="tableData"
            height="100%"
            style="width: 100%;"
            ref="tempLateName"
        >
            <el-table-column
                type="index"
                label="序号"
                align="center"
                width="80"
            />
            <el-table-column
                prop="true_name"
                label="使用人昵称"
                show-overflow-tooltip
                align="left"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="phone"
                label="使用人手机号"
                show-overflow-tooltip
                align="center"
                :formatter="emptyFormatter"
            />
            <el-table-column
                prop="order_no"
                label="订单号"
                show-overflow-tooltip
                align="center"
                width="240"
            />
            <el-table-column
                prop=""
                label="使用时间"
                show-overflow-tooltip
                align="center"
            >
                <template slot-scope="scope">
                    {{ scope.row.use_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop=""
                label="退回时间"
                show-overflow-tooltip
                align="center"
            >
                <template slot-scope="scope">
                    {{ scope.row.back_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                </template>
            </el-table-column>
            <el-table-column
                prop=""
                label="退回原因"
                align="center"
                :formatter="emptyFormatter"
            >
                <template slot-scope="scope">
                    <div v-if="scope.row.back_type === 1">用户退款</div>
                    <div v-if="scope.row.back_type === 2">用户退款退货</div>
                    <div v-if="scope.row.back_type === 3">取消订单</div>
                </template>
            </el-table-column>
        </el-table>
        <!-- /table -->

        <!-- 分页 -->
        <div class="pagination-wrapper clearfix">
            <el-pagination
                layout="total, prev, pager, next, jumper"
                :current-page.sync="page.now_page"
                :total="page.total_count"
                :page-size="page.page_size"
                @current-change="getTableData"
            />
        </div>
    </div>
</template>

<script>
export default {
    name: "ReturnRecord",
    props: {
        couponNo: {
            type: String,
            required: true
        },
    },
    data() {
        return {
            filterData: {
                filterType: '1',
                keyword: '',
                // 退回原因
                back_type: ''
            },
            tableData: [],
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            reasonList: [
                {label: '全部', value: ''},
                {label: '用户退款', value: 1},
                {label: '用户退款退货', value: 2},
                {label: '取消订单', value: 3},
            ]
        };
    },
    mounted() {
        this.getTableData();
    },
    methods: {

        /**
         * 获取表格数据
         * @param page
         */
        getTableData(page) {

            let params = {...this.filterData};

            params.coupon_no = this.couponNo;
            params.page_id = page || this.page.now_page;
            this.$post('/student/shop_goods_coupon%5Cget_back_list', params, resp => {
                if (resp.code === 1) {
                    this.tableData = resp.data.list;
                    this.page = resp.data.page;
                } else {
                    this.$notify({
                        title: '失败',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },
        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },
    }
};
</script>

<style scoped lang="less">
.wrapper {
    display: flex;
    height: calc(100% - 24px);
    width: calc(100% - 48px);
    flex-direction: column;
    position: relative;
    margin: 0 24px 24px;
    background: #fff;
    box-sizing: border-box;

    /*筛选表单*/
    .filter-view {
        margin: 6px 0 10px;
        display: flex;
        .header-new-box {
            display: flex;
            align-items: center;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
            white-space: nowrap;
            margin-right: 24px;
            margin-bottom: 16px;

            &-title {
                margin-right: 16px;
                white-space: nowrap;
            }
        }
    }

    /* 分页 */
    .pagination-wrapper {
        padding: 10px 32px;

        .el-pagination {
            float: right;
            padding: 0;
            background-color: transparent;
        }
    }
}
</style>

